package com.cxm.helper.controller.admin;

import cn.dev33.satoken.annotation.SaCheckRole;
import com.cxm.helper.pojo.Article;
import com.cxm.helper.pojo.dto.ArticleUpdateStatusDTO;
import com.cxm.helper.service.ArticleService;
import com.cxm.helper.util.ResponseEntity;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author: chenximeng
 * @date: 2022/11/24 11:10
 */
@RestController
@RequestMapping("/admin/article")
@SaCheckRole("admin")
public class ArticleAdminController {

    @Autowired
    ArticleService articleService;

    @PostMapping("/updateStatus")
    public ResponseEntity updateStatus(@RequestBody ArticleUpdateStatusDTO articleUpdateStatusDTO){
        Article article = new Article();
        BeanUtils.copyProperties(articleUpdateStatusDTO, article);
        articleService.updateById(article);
        return ResponseEntity.ok();
    }

    @DeleteMapping("/delete/{id}")
    public ResponseEntity delete(@PathVariable Long id) {
        articleService.removeById(id);
        return ResponseEntity.ok();
    }
}
